#pragma once
#include "hash.h"

namespace xy {
	template<class K, class V>
	struct MaptKeyOfT {
		const K& operator()(const pair<const K, V>& k) {
			return k.first;
		}
	};

	template<class K, class V>
	class unordered_map {
	public:
		typedef hashTable<K, pair<const K, V>, MaptKeyOfT<K, V>> hash;
		typedef typename hash::iterator iterator;
		typedef typename hash::const_iterator const_iterator;

		iterator begin() {
			return _ht.begin();
		}

		iterator end() {
			return _ht.end();
		}

		const_iterator begin() const{
			return _ht.begin();
		}

		const_iterator end() const{
			return _ht.end();
		}

		iterator find(const K& k) {
			return _ht.find(k);
		}

		pair<iterator, bool> insert(const pair<const K, V>& k) {
			return _ht.insert(k);
		}

		bool erase(const K& k) {
			return _ht.erase(k);
		}

		V& operator[](const K& k) {
			pair<iterator, bool> ret = insert(make_pair(k, V()));
			return ret.first->second;
		}

		void print() {
			_ht.map_print();
			cout << endl;
		}
	private:
		hash _ht;
	};
}